// 产品公用JS

$(function() {

  wrapForm('litPic','Product');
  wrapForm('bigPic','Product');
  wrapForm('headerImg','Product');

  $('#dataTables').dataTable({
      paging: false,
      scrollY: 400,
      order: [[ 2, "desc" ]],
      columnDefs: [ {
          targets: 9,
          orderable: false  //如果第一列进行排序，有相同数据则按照第二列顺序排列
        } ],
      language: {
          "sProcessing": "处理中...",
          "sLengthMenu": "显示 _MENU_ 项结果",
          "sZeroRecords": "没有匹配结果",
          "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
          "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
          "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
          "sInfoPostFix": "",
          "sSearch": "高级搜索:",
          "sUrl": "",
          "sEmptyTable": "表中数据为空",
          "sLoadingRecords": "载入中...",
          "sInfoThousands": ",",
          "oPaginate": {
              "sFirst": "首页",
              "sPrevious": "上页",
              "sNext": "下页",
              "sLast": "末页"
          },
          "oAria": {
              "sSortAscending": ": 以升序排列此列",
              "sSortDescending": ": 以降序排列此列"
          }
      }
    });

});


/**
 * [wrapForm description]
 * @param  {[type]} id   [description]
 * @param  {[type]} type [description]
 * @return {[type]}      [description]
 */
function wrapForm (id,type)
{
  $("#"+id).wrap("<form class='uploadImg' action='/Home/Public/uploadPic/fileType/Img/type/"+type+".html' method='post' enctype='multipart/form-data'></form>");
}
/**
 * [uploadPic description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function uploadPic(obj,name)
{
  if($(obj).val() == "") return;

  $(obj).parent().ajaxSubmit({
      dataType:  'json',
      beforeSend: function() {
        $(obj).parent().parent().find('.fileupload').empty();
        $(obj).parent().parent().find('.fileupload').html("正在上传中...");
      },
      success: function(data) {

        if(data.state == 'SUCCESS')
        {
            $(obj).parent().parent().find('.fileupload').empty();
            $(obj).parent().parent().find('.fileupload').html("<img src='http://www.tripvip.cn"+data.url+"' width='120' height='120'>");
            $(obj).parent().parent().find('.fileupload').append("<input type='hidden' name='"+name+"' class='headerImg' value='"+data.url+"'>");
        }
        else
        {
            $(obj).parent().parent().find('.fileupload').html(data.msg);
        }
    },
    error:function(xhr){
      $(obj).parent().parent().find('.fileupload').html('上传失败!');
      $(obj).parent().parent().find('.fileupload').html(xhr);
    }
  });
}

/**
 * [currLabel description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function currLabel(obj)
{
  if($(obj).is(':checked') == true)
    {
      $(obj).parent().find('span').css({
        'background-color' : '#59bc5e'
      });
    }
    else
    {
      $(obj).parent().find('span').css({
        'background-color' : '#CCC'
      });
    }
}

/**
 * [currProductLabel description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function currProductLabel(obj,id,name)
{
  if($(obj).is(':checked') == true)
  {
    $(obj).parent().find('span').css({
      'background-color' : '#59bc5e'
    });
    var html = '';
        html += '<span class="pro-span">'+name;
          html += '<input type="hidden" name="labelID[]" value="'+id+'">';
          html += '<a href="javascript:;" onclick="delCurrLabel(this,\''+id+'\')" style="color:#FFF;">X</a>';
        html += '</span>';
      $('#classLabel').append(html);
  }
  else
  {
    $(obj).parent().find('span').css({
      'background-color' : '#CCC'
    });
    var object = $('input[value="'+id+'"]').parent();
    $('#classLabel').find(object).remove();
  }
}

/**
 * [delCurrLabel description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function delCurrLabel (obj,id)
{
  $('input[name="label[]"]').each(function (index) {

    if($(this).val() == id)
    {
      $(this).parent().find('span').css({
        'background-color': '#CCC'
      });
    }

  });

  $(obj).parent().remove();

}
/**
 * [destinationSelect description]
 * @return {[type]} [description]
 */
function destinationSelect(obj)
{
  var destinationID = $(obj).val();
  if(destinationID == '0')
  {
    $(obj).nextAll('select').find('option').not('option[value="0"]').remove();
    return;
  }
  $.ajax({
    url: "/Home/Webproduct/destinationDataAjax",
    type: 'POST',
    dataType: 'json',
    data: {'destinationID': destinationID},
    success:function  (data) {

      $(obj).nextAll('select').find('option').not('option[value="0"]').remove();
      $(obj).next('select').append(data.destinationChildHtml);

    }
  })
}


/**
 * [submitAddProduct description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
 function submitAddProduct(obj)
 {
    var AddProduct = $(obj).parent().parent();
    var id         = AddProduct.find('.id').val();
    var productID  = "{$id}";
    var img        = AddProduct.find('.headerImg').val();
    var price      = AddProduct.find('.price').val();

    if(AddProduct.find('input[type="radio"]:last').is(':checked') == true)
    {
      var sumType = AddProduct.find('.custom').val();
    }
    else
    {
      var sumType = AddProduct.find('input[type="radio"]:checked').val();
    }

    var name       = AddProduct.find('.name').val();
    var content    = AddProduct.find('.content').val();

    $.ajax({
      url: "/Home/Webproduct/submitAddProduct",
      type: 'post',
      dataType: 'json',
      data: {'productID': productID,'id': id,'img': img,'price': price,'sumType': sumType,'name': name,'content': content},
      success:function  (data)
      {
          if(data.status == 1)
          {
            location.reload();
          }
      }
    })
 }

/**
 * [destinationHtmlDel description]
 * @return {[type]} [description]
 */
function destinationHtmlDel(obj)
{
  $(obj).parent().parent().remove();
}
/**
 * [departureCityAdd description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function departureCityAdd (obj)
{

  var html = '';
      html+='<div class="ly-addbox" id="selectProduct">';
        html+='<p class="mt10"><label class="label-180">请输入关联的产品ID：</label> <input type="text" name="libraryID" onkeyup="getLibrary(this)" /><span id="departureName"></span></p>';
        html+='<p class="mt10" id="libraryTitle" style="text-align: center;"></p>';
        html+='<p class="mt10">';
          html+='<label class="label-180">请选择加价幅度：</label>';
          html+='<select name="addPriceType" style="padding:2px 12px;">';
          html+='<option value="0" selected>成本价</option>';
          html+='<option value="1">手动输入加价额度</option>';
          html+='<option value="2">按成本百分比加价</option>';
        html+='</select>';
        html+='</p>';
        html+='<p class="mt10">';
          html+='<label class="label-180">&nbsp;</label>';
          html+='<input type="text" name="Increase" value="">';
        html+='</p>';
      html+='</div>';

  //页面层-自定义
  var Div = layer.open({
      type: 1,
      title: '添加出发地',
      area: ['450px', '260px'],
      shift: 0, //从左动画弹出
      content: html,
      btn:['确定','取消'],
      yes: function(index){
          // currLibrary(obj);
          var libraryID     = $('#selectProduct').find('input[name="libraryID"]').val();
          $.ajax({
             url: "/Home/Webproduct/getLibraryAjax",
             type: 'post',
             dataType: 'json',
             data: {'libraryID': libraryID},
             success:function (data) {
               if(data.valid == true)
               {
                 currLibrary(obj,libraryID,data.libraryTitle,data.departureName,data.price);
                 layer.close(Div);
               }
             }
           })
      },
      cancel: function(){
        layer.close(Div);
      }
  });
}

/**
 * [changePriceType description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function changePriceType(obj,price)
{

  var keyCode = event.which;
  if ((keyCode >= 37 && keyCode <=40) || keyCode == 110 || keyCode == 190)
  {
    return;
  }
  else
  {
    var libraryID    = $(obj).parent().find('input[name="libraryID[]"]').val();
    var addPriceType = $(obj).parent().find('select[name="addPriceType[]"]').val();
    var addPriceNums = $(obj).parent().find('input[name="addPriceNums[]"]').val();

    var sellPrice    = '';
    switch (addPriceType)
    {
      case '0':
        sellPrice = price;
        $(obj).find('option[value="0"]').attr('selected',true);
        $(obj).find('option').not('option[value="0"]').removeAttr('selected');
        $(obj).parent().find('input[name="addPriceNums[]"]').val('');
        $(obj).parent().find('input[name="addPriceNums[]"]').attr('disabled','disabled');
        break;

      case '1':
        $(obj).find('option[value="1"]').attr('selected',true);
        $(obj).find('option').not('option[value="1"]').removeAttr('selected');
        if(isNaN(parseInt(addPriceNums)))
        {
          sellPrice = price;
          $(obj).parent().find('input[name="addPriceNums[]"]').val(addPriceNums);
        }
        else
        {

          sellPrice = parseInt(price) + parseInt(addPriceNums);
          $(obj).parent().find('input[name="addPriceNums[]"]').val(parseInt(addPriceNums));
        }
        $(obj).parent().find('input[name="addPriceNums[]"]').removeAttr('disabled');
        break;

      case '2':
          $(obj).find('option[value="2"]').attr('selected',true);
          $(obj).find('option').not('option[value="2"]').removeAttr('selected');
          if(isNaN(parseInt(addPriceNums)))
          {
            sellPrice = price;
            $(obj).parent().find('input[name="addPriceNums[]"]').val(addPriceNums);
          }
          else
          {

            sellPrice =  Math.ceil(parseInt(price) + (parseInt(price) * parseInt(addPriceNums)*0.01),0);
            $(obj).parent().find('input[name="addPriceNums[]"]').val(parseInt(addPriceNums));
          }

        $(obj).parent().find('input[name="addPriceNums[]"]').removeAttr('disabled');
        break;
    }
    $(obj).parent().find('.sellPrice').html(sellPrice);
    $('#libraryID_'+libraryID).find('dd font').html(costPrice);
  }

}
/**
 * [getLibrary description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function  getLibrary(obj)
{
  var libraryID = $(obj).val();
  var i = 0;
  $('input[name="libraryID[]"]').each(function (index) {

    if($(this).val() == libraryID)
    {
      i++;
    }

  });

  if(i == 0 )
  {

   $.ajax({
     url: "/Home/Webproduct/getLibraryAjax",
     type: 'post',
     dataType: 'json',
     data: {'libraryID': libraryID},
     success:function (data) {
       if(data.valid == true)
       {
          $('#departureName').empty();
          $('#departureName').html(data.departureName);
          $('#libraryTitle').empty();
          $('#libraryTitle').html(data.libraryTitle);
       }
       else
       {
          $('#departureName').empty();
          $('#libraryTitle').empty();
       }
     }
   })
  }
  else
  {
    $('#selectProduct').find('input[name="libraryID"]').val('')
    $('#departureName').empty();
    $('#libraryTitle').empty();
  }


}

/**
 * [currProduct description]
 * @return {[type]} [description]
 */
function currLibrary(obj,libraryID,libraryTitle,departureName,price)
{
  var addPriceType = $('#selectProduct').find('select[name="addPriceType"]').val();
  var Increase     = $('#selectProduct').find('input[name="Increase"]').val();

  price            = Math.ceil(price,0);
  var sellPrice    = '';
  var html = '';
      html += '<div class="operateDeparture">';
        html += '<input type="text" class="inp_small" name="libraryID[]" value="'+libraryID+'" readonly="readonly" >';
        html += '<input type="text" class="inp_default" name="libraryTitle[]" value="'+libraryTitle+'" readonly="readonly" style="margin-left: 5px;">';
        html += '<span style="margin-left: 5px;" >'+departureName+'</span>';
          switch (addPriceType)
          {
              case '0':
                html += '<select name="addPriceType[]" onchange="changePriceType(this,\''+price+'\')" style="padding:2px 12px;">';
                  html += '<option value="0" selected>成本价</option>';
                  html += '<option value="1">手动输入加价额度</option>';
                  html += '<option value="2">按成本百分比加价%</option>';
                html += '</select>';
                html += '<input type="text" name="addPriceNums[]" onkeyup="changePriceType(this,\''+price+'\')" style="width:50px;" disabled > &nbsp;&nbsp;';
                sellPrice = price;
                break;

              case '1':
                html += '<select name="addPriceType[]" onchange="changePriceType(this,\''+price+'\')" style="padding:2px 12px;">';
                  html += '<option value="0">成本价</option>';
                  html += '<option value="1" selected>手动输入加价额度</option>';
                  html += '<option value="2">按成本百分比加价%</option>';
                html += '</select>';

                  if(isNaN(parseInt(Increase)))
                  {
                    html += '<input type="text" name="addPriceNums[]" onkeyup="changePriceType(this,\''+price+'\')"  style="width:50px;" value="'+Increase+'"> &nbsp;&nbsp;';
                    sellPrice = price;
                  }
                  else
                  {

                    html += '<input type="text" name="addPriceNums[]" onkeyup="changePriceType(this,\''+price+'\')"  style="width:50px;" value="'+parseInt(Increase)+'"> &nbsp;&nbsp;';
                    sellPrice = parseInt(price) + parseInt(Increase);
                  }

                break;

              case '2':
                html += '<select name="addPriceType[]" onchange="changePriceType(this,\''+price+'\')"  style="padding:2px 12px;">';
                  html += '<option value="0">成本价</option>';
                  html += '<option value="1">手动输入加价额度</option>';
                  html += '<option value="2" selected>按成本百分比加价%</option>';
                html += '</select>';

                  if(isNaN(parseInt(Increase)))
                  {
                    html += '<input type="text" name="addPriceNums[]" onkeyup="changePriceType(this,\''+price+'\')"  style="width:50px;" value="'+paIncrease+'"> &nbsp;&nbsp;';
                    sellPrice =  price;
                  }
                  else
                  {

                    html += '<input type="text" name="addPriceNums[]" onkeyup="changePriceType(this,\''+price+'\')"  style="width:50px;" value="'+parseInt(Increase)+'"> &nbsp;&nbsp;';
                    sellPrice =  Math.ceil(parseInt(price) + (parseInt(price) * parseInt(Increase))/100,0);
                  }
                break;
          }
        html += '<font class="font-green sellPrice">'+sellPrice+'元</font> &nbsp;&nbsp;';
        html += '<a href="javascript:;" onclick="departureCityDel(this,\''+libraryID+'\')">删除</a>';
      html += '</div>';

  $(obj).before(html);

  var pricelistHrml = '';
      pricelistHrml+= '<dl id="libraryID_'+libraryID+'">';
        pricelistHrml+= '<dt>'+departureName+'出发</dt>';
        pricelistHrml+= '<dd><font class="red" style="font-size:24px;">'+sellPrice+'</font>元</dd>';
      pricelistHrml+= '</dl>';

  $('.pricelist').append(pricelistHrml);
}
/**
 * [departureCityDel description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function departureCityDel (obj,id)
{
  $(obj).parent().remove();
  $('#libraryID_'+id).remove();
}
/**
 * [submitDo description]
 * @return {[type]} [description]
 */
function submitDo()
{
  if($('input[name="title"]').length > 0)
  {
    if($('input[name="title"]').val().length > 0)
    {
      $('input[name="title"]').css('border','1px green solid');
      $('#form_do').submit();
    }
    else
    {
      $('input[name="title"]').css('border','1px red solid');
    }
  }
  else
  {
    $('#form_do').submit();
  }

}
/**
 * [categoryLabelList description]主站分类标签分类
 * @return {[type]} [description]
 */
 function categoryLabelList (obj)
 {

   $.ajax({
     url: "/Home/Webproduct/categoryLabelList",
     type: 'get',
     dataType: 'json',
     data: {'id': $(obj).val()},
     success:function  (data)
     {
       $('#categoryLabelList').html(data.html);
     }
   })
 }

/**
 * [packCategory description]主站分类
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
 function packCategory (obj)
 {
   var packCategoryOne = $(obj).val();
   $(obj).next('select[name="packCategoryTwo"]').find('option').not('option[value="0"]').remove();
   if(packCategoryOne == 0)return;
   $.ajax({
     url: "/Home/Webproduct/packCategoryAjax",
     type: 'get',
     dataType: 'json',
     data: {'packCategoryOne': packCategoryOne},
     success:function (data)
     {
       $(obj).next('select[name="packCategoryTwo"]').append(data.html);
     }
   })

 }

/**
 * [getLabel description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function getLabel()
{
  var id       = $('select[name="productLabelClassID"]').val();
  var keyWords = $('input[name="labelKeyWords"]').val();

  var currID   = new Array();
  $('input[name="labelID[]"]').each(function (index) {

    currID[index] = $(this).val();

  });

  $.ajax({
    url: "/Home/Webproduct/getClassLabel",
    type: 'post',
    dataType: 'json',
    data: {'id': id,'currID':currID,'keyWords':keyWords},
    success:function (data) {

      if(data.valid == true)
      {
        $('#labellist').empty();
        $('#labellist').append(data.data);
      }
      else
      {
        layer.msg(data.state, {icon: 2});
      }
    }
  })
}

/**
 * [destination description]
 * @param  {[type]} o    [description]
 * @param  {[type]} type [description]
 * @return {[type]}      [description]
 */
function destinationChange (o,type)
{
  var div = $(o).parent();
  var get = {};
  var obj = $(o);
  if(obj.val() == 0)
  {
    obj.nextAll('select').val('0');
    return;
  }

  if(type==1)
  {
  get.continent = div.find('[name="areaID"]').val();
    obj = div.find('[name="countryID"]');
  }
  else if(type==2)
  {
    get.country = div.find('[name="countryID"]').val();
    obj = div.find('[name="cityID"]');
  }
  else
  {
    return false;
  }

  $.get('/Home/Public/ajaxDestination',get, function (data, textStatus){
    obj.html(data);
  });
}

/**
 * [iframeSrc description]
 * @param  {[type]} iframeSrc [description]
 * @return {[type]}           [description]
 */
function iframeSrcDepartureDate(iframeSrc,productTitle)
{
    //iframe层-禁滚动条
    layer.open({
        type: 2,
        title: productTitle,
        area: ['650px', '320px'],
        maxmin: true,
        skin: 'layui-layer-rim', //加上边框
        content: [iframeSrc, 'no'],

    });
}
/**
 * [selectDepartureDate description]
 * 出行日期筛选
 * @return {[type]} [description]
 */
function selectDepartureDate(obj,id,step)
{
  var libraryID = $(obj).val();
  window.location.href = '/Home/Webproduct/selledit/id/'+id+'/step/'+step+'/libraryID/'+libraryID;
}


/**
 * [iframeSrc description]
 * 酒店信息编辑
 * @param  {[type]} iframeSrc [description]
 * @return {[type]}           [description]
 */
function iframeSrcHotel(iframeSrc,productTitle)
{
    //iframe层-禁滚动条
    layer.open({
        type: 2,
        title: productTitle,
        area: ['1100px', '750px'],
        maxmin: true,
        skin: 'layui-layer-rim', //加上边框
        content: [iframeSrc, 'no'],

    });
}
/**
 * [iframeSrcTravelreference description]
 * 行程信息编辑
 * @param  {[type]} iframeSrc    [description]
 * @param  {[type]} productTitle [description]
 * @return {[type]}              [description]
 */
function iframeSrcTravelreference (iframeSrc,productTitle)
{
  //iframe层-禁滚动条
    layer.open({
        type: 2,
        title: productTitle,
        area: ['1000px', '650px'],
        maxmin: true,
        skin: 'layui-layer-rim', //加上边框
        content: [iframeSrc, 'no'],

    });
}

/**
 * [iframeSrcAirplaneInfo description]
 * @param  {[type]} iframeSrc    [description]
 * @param  {[type]} productTitle [description]
 * @return {[type]}              [description]
 */
function iframeSrcAirplaneInfo (iframeSrc,productTitle)
{
  //iframe层-禁滚动条
  layer.open({
      type: 2,
      title: productTitle,
      area: ['1000px', '550px'],
      maxmin: true,
      skin: 'layui-layer-rim', //加上边框
      content: [iframeSrc, 'no'],

  });
}

/**
 * [airLineSet description]
 * @return {[type]} [description]
 */
function airLineSet(productID,productTitle,action,id)
{
  var data = airLineAjax(id);
  var html = '';
      html+='<div class="form" style="min-height:0;">';
        html+='<form method="post" id="form" action="'+action+'" >';
              html+='<dl>';
                html+='<dt> 产品标题：</dt>';
                html+='<dd>';
                  html+='<input type="text" name="productTitle" class="inp_default" value="'+productTitle+'" readonly="readonly"/>';
                html+='</dd>';
              html+='</dl>';
              html+='<dl>';
                html+='<dt> 航线名称：</dt>';
                html+='<dd>';
                  html+='<input type="text" name="title" class="inp_default" value="'+data.info.title+'" />';
                html+='</dd>';
              html+='</dl>';
              html+='<dl>';
                html+='<dt> 描述：</dt>';
                html+='<dd>';
                  html+='<textarea name="description" class="tarea_default">'+data.info.description+'</textarea>';
                html+='</dd>';
              html+='</dl>';
              html+='<dl>';
                html+='<dt> 排序：</dt>';
                html+='<dd>';
                  html+='<input type="text" name="sort" class="inp_small" value="'+data.info.sort+'" />';
                html+='</dd>';
              html+='</dl>';
              html+='<dl>';
                html+='<dt> </dt>';
                html+='<dd>';
                  html+='<input type="button" class="button-green" onClick="airLineSetSubmit()" value="保 存" />';
                html+='</dd>';
              html+='</dl>';
          html+='</form>';
        html+='</div>';

  //页面层-自定义
  layer.open({
      type: 1,
      title: productTitle,
      area: ['600px', '346px'],
      maxmin: true,
      content: html
  });
}

/**
 * [airLineAjax description]
 * @param  {[type]} id [description]
 * @return {[type]}    [description]
 */
function airLineAjax(id)
{
  var result = {'info':{'title': '','description': '','sort': '255'}};
  if(id)
  {
      $.ajax({
          url: "/Home/Webproduct/airpLineSet",
          type: 'post',
          dataType: 'json',
          async:false,
          data: {'id': id ,'type' : 'airline'},
          success:function (data) {
             result = data;
          }
        })
  }
  return result;
}

/**
 * [airLineSetSubmit description]
 * @return {[type]} [description]
 */
function airLineSetSubmit()
{
    $('#form').ajaxSubmit({
      dataType:  'json',
      success:function (data) {
        if(data.valid == true)
        {
          layer.msg(data.state);
          window.parent.document.location.reload();
        }
        else
        {
          layer.msg(data.state);
        }
      }
    })
}

function productTypeAjax (type,productID)
{

  $.ajax({
    url: '/Home/Webproduct/productTypeAjax',
    type: 'post',
    dataType: 'json',
    data: {'type': type},
    success:function  (data) {
      if(data.valid == true)
      {
        productTypeList(type,productID,data.info);
      }
      else
      {
        layer.confirm(data.state, {
            btn: ['去添加','取消'] //按钮
        }, function(){
            window.location.href= "/Home/Product/singleEdit";
        });
      }
    }
  })

}
/**
 * [productTypeList description]
 * @return {[type]} [description]
 */
function productTypeList(type,productID,list)
{
  var productTypeName = '';

  switch (type)
  {
    case '1':
      productTypeName = '附加保险';
      break;
    case '2':
      productTypeName = '附加产品';
      break;
    case '3':
      productTypeName = '包含单品';
      break;
    case '4':
      productTypeName = '赠送单品';
      break;
    case '5':
      productTypeName = '当地游';
      break;
    case '6':
      productTypeName = '优惠券';
      break;
  }
  var html = '';
      html+='<table class="list" id="dataTables">';
        html+='<thead>';
          html+='<tr>';
            html+='<th class="center">标题</th>';
            html+='<th class="center">图片</th>';
            html+='<th class="center">价格</th>';
            html+='<th class="center">操作</th>';
          html+='</tr>';
        html+='</thead>';
        html+='<tbody id="list_pp">';

          for (var i = 0; i < list.length; i++)
          {
            html+='<tr>';
                  html+='<td class="left">'+list[i].title+'</td>';
                  html+='<td class="center"><img src="http://www.tripvip.cn'+list[i].uploadImg+'"  width="100" height="80"/></td>';
                  html+='<td class="center">'+list[i].price+'</td>';
                  html+='<td class="center"><a href="javascript:;" onclick="getProductTypeHtml(\''+type+'\',\''+productID+'\',\''+productTypeName+'\',\''+list[i].id+'\',\''+list[i].title+'\')">添加</a></td>';
            html+='</tr>';
          }

        html+='</tbody>';
      html+='</table>';

  //页面层-自定义
  var Div = layer.open({
      type: 1,
      title: productTypeName,
      shade: 0.8,
      area: ['80%', '80%'],
      shift: 0, //从左动画弹出
      content: html,
      maxmin: true
  });
}

/**
 * [getProductType description]
 * @param  {[type]} id [description]
 * @return {[type]}    [description]
 */
function getProductTypeHtml(type,productID,productTypeName,containID,title,id)
{
  var area = ['60%', '60%'];
  var html = '';

  switch (type)
  {
      case '2':
        html+='<div class="form" style="min-height:0;">';
          html+='<dl>';
              html+='<dt>'+productTypeName+'ID</dt>';
              html+='<dd><input type="text" name="containID" class="inp_default" value="'+containID+'"  readonly="readonly"></dd>';
            html+='</dl>';
          html+='<dl>';
            html+='<dt></dt>';
            html+='<dd><input type="text" name="title" class="inp_default" value="'+title+'"  readonly="readonly" ></dd>';
          html+='</dl>';
          html+='<dl>';
              html+='<dt>购买数量</dt>';
              html+='<dd>';
                  html+='<input type="radio" name="buyType" value="0" onChange="radioCurr(this)"><span>默认购买</span>';
                  html+='<input type="radio" name="buyType" value="O" onChange="radioCurr(this)"><span>一个</span>';
                  html+='<input type="radio" name="buyType" value="V" onChange="radioCurr(this)"><span>游客总数</span>';
                  html+='<input type="radio" name="buyType" value="T" onChange="radioCurr(this)"><span>成人总数</span>';
                  html+='<input type="radio" name="buyType" value="C" onChange="radioCurr(this)">';
                  html+='<span>自定义</span><input type="text" name="buyType" class="custom" style=" width: 50px;" disabled="disabled">';
              html+='</dd>';
          html+='</dl>';
          html+='<dl>';
              html+='<dt>设置加价幅度</dt>';
              html+='<dd><input type="text" name="upPrice" class="inp_small" value="" >元</dd>';
            html+='</dl>';
        html+='</div>';
        area = ['550px', '300px'];
        break;

      default:
        html+='<div class="form" style="min-height:0;">';
            html+='<dl>';
              html+='<dt>'+productTypeName+'ID</dt>';
              html+='<dd><input type="text" name="containID" class="inp_default" value="'+containID+'"  readonly="readonly"></dd>';
            html+='</dl>';
            html+='<dl>';
              html+='<dt></dt>';
              html+='<dd><input type="text" name="title" class="inp_default" value="'+title+'"  readonly="readonly" ></dd>';
            html+='</dl>';
            html+='<dl>';
              html+='<dt>设置加价幅度</dt>';
              html+='<dd><input type="text" name="upPrice" class="inp_small" value="" >元</dd>';
            html+='</dl>';
        html+='</div>';
        area = ['450px', '250px'];
        break;
    }

  //自定页
  var Div = layer.open({
              title: title,
              type: 1,
              shift: 2,
              area: area,
              shadeClose: true, //开启遮罩关闭
              content: html,
              btn:['确定','取消'],
              yes: function(index){
                getProductType(Div,type,productID,id);
              },
              cancel: function(){
                layer.close(Div);
              }
          })
}

/**
 * [getProductType description]
 * @param  {[type]} obj       [description]
 * @param  {[type]} type      [description]
 * @param  {[type]} productID [description]
 * @return {[type]}           [description]
 */
function getProductType (obj,type,productID,id)
{
  var containID = $('input[name="containID"]').val();
  var upPrice   = $('input[name="upPrice"]').val();
  var buyType   = $('input[name="buyType"]:checked').val();
  if(buyType == 'C')
  {
    buyType = $('input[name="buyType"]:checked').parent().find('.custom').val();
  }

  $.ajax({
      url: '/Home/Webproduct/getProductType',
      type: 'post',
      dataType: 'json',
      data: {'id': id, 'type': type ,'productID': productID, 'containID': containID, 'upPrice': upPrice,'buyType': buyType},
      success:function (data) {
        if(data.valid == true)
        {
          layer.msg(data.state);
          layer.close(obj);
          window.location.reload();
        }
        else
        {
          layer.msg(data.state);
        }
      }
    })
}

/**
 * [getProductTypeDel description]
 * @param  {[type]} id [description]
 * @return {[type]}    [description]
 */
function getProductTypeDel(id)
{
  $.ajax({
      url: '/Home/Webproduct/getProductTypeDel',
      type: 'post',
      dataType: 'json',
      data: {'id': id},
      success:function (data) {
        if(data.valid == true)
        {
          layer.msg(data.state);
          window.location.reload();
        }
        else
        {
          layer.msg(data.state);
        }
      }
    })
}

function radioCurr(obj)
{
  if($(obj).attr('checked') == 'checked' && $(obj).val() == 'C')
  {
    $(obj).parent().find('.custom').removeAttr('disabled');
  }
  else
  {
    $(obj).parent().find('.custom').attr('disabled','disabled');
  }
}